web/src/pages/[...listing].astro

477 lines · 13409 bytes

  1---
  2import Layout from '@layouts/Layout.astro';
  3import ListingHero from '@components/things/ListingHero.astro';
  4import ServiceList from '@components/things/ServiceList.astro';
  5import Comments from '@components/things/Comments.svelte';
  6import GitHubDetailedInfo from '@components/things/GitHubDetailedInfo.astro';
  7import PrivacyPolicyDetails from '@components/things/PrivacyPolicyDetails.astro';
  8import WebsiteDetailedInfo from '@components/things/WebsiteDetailedInfo.astro';
  9import DockerDetailedInfo from '@components/things/DockerDetailedInfo.astro';
 10import IosAppDetailedInfo from '@components/things/IosAppDetailedInfo.astro';
 11import AndroidAppDetailedInfo from '@components/things/AndroidDetailedInfo.astro';
 12import DiscordDetailedInfo from '@components/things/DiscordDetailedInfo.astro';
 13import RedditDetailedInfo from '@components/things/RedditDetailedInfo.astro';
 14import SocialShare from '@components/form/Social.astro';
 15import DataActions from '@components/things/DataActions.svelte';
 16import type { AwesomePrivacy, Section, Service } from '../types/Service';
 17import { fetchData, slugify } from '@utils/fetch-data';
 18import { fetchChangelog } from '@utils/fetch-changelog';
 19import { fetchGitHubStats } from '@utils/fetch-repo-info';
 20import { fetchTosdrPrivacy } from '@utils/fetch-privacy-policy';
 21import { fetchWebsiteInfo } from '@utils/fetch-website-info';
 22import { fetchDockerData } from '@utils/fetch-docker-instructions';
 23import { fetchIosInfo } from '@utils/fetch-ios-info';
 24import { fetchAndroidInfo } from '@utils/fetch-android-info';
 25import { fetchDiscordInfo } from '@utils/fetch-discord-info';
 26import { fetchRedditInfo } from '@utils/fetch-reddit-info';
 27import { site } from '@utils/config';
 28import Button from '@components/form/Button.astro';
 29
 30interface Props extends Service {
 31	slug: string;
 32	parentSection: Section;
 33	categoryName: string;
 34}
 35
 36const {
 37	name,
 38	description,
 39	url,
 40	github,
 41	tosdrId,
 42	discordInvite,
 43	subreddit,
 44	iosApp,
 45	androidApp,
 46	parentSection,
 47	categoryName,
 48} = Astro.props;
 49
 50const makeKeyWordTag = () => {
 51	const keywords = [
 52		`open source ${parentSection.name}`,
 53		`${parentSection.name} comparison`,
 54		...(parentSection.alternativeTo || []).map(
 55			(alt: string) => `${alt} alternative`,
 56		),
 57		...(parentSection.services || []).map((serv: Service) => `${serv.name} vs`),
 58		'private',
 59		'ad free',
 60		'encrypted',
 61		'open source software',
 62		'privacy respecting apps',
 63		'free tools',
 64	];
 65	return keywords.join(', ');
 66};
 67
 68const makePageTitle = () => {
 69	return `${name} | ${parentSection.name} | ${categoryName} | Awesome Privacy`;
 70};
 71
 72const makeBreadcrumbs = () => {
 73	return [
 74		{ name: 'Home', item: '/' },
 75		{ name: categoryName, item: slugify(categoryName) },
 76		{
 77			name: parentSection.name,
 78			item: `${slugify(categoryName)}/${slugify(parentSection.name)}`,
 79		},
 80		{
 81			name: name,
 82			item: `${slugify(categoryName)}/${slugify(parentSection.name)}/${slugify(name)}`,
 83		},
 84	];
 85};
 86
 87const makeDescriptionTag = () => {
 88	let desc = `Analysis of ${name}, and other privacy-respecting ${parentSection.name} `;
 89	if (parentSection.services) {
 90		desc += `Compare ${parentSection.services.map((s: Service) => s.name).join(' vs ')} more apps. `;
 91	}
 92	if (parentSection.alternativeTo && parentSection.alternativeTo.length > 0) {
 93		desc += `The best secure encrypted alternatives to ${parentSection.alternativeTo.join(', ')}. `;
 94	}
 95	desc += 'All this, and many more free and awesome tools and software.';
 96	return desc;
 97};
 98
 99const filterServices = () => {
100	return parentSection.services.filter((s: Service) => s.name !== name);
101};
102
103export async function getStaticPaths() {
104	const pages = await fetchData().then((data) => {
105		const results: Array<Props> = [];
106		if (!data || !data.categories) return results;
107		(data as AwesomePrivacy).categories.forEach((category) => {
108			category.sections.forEach((section) => {
109				const services = (section.services || []).map((service) => {
110					return {
111						slug: `${slugify(category.name)}/${slugify(section.name)}/${slugify(service.name)}`,
112						parentSection: section,
113						categoryName: category.name,
114						...service,
115					};
116				});
117				results.push(...services);
118			});
119		});
120		return results;
121	});
122
123	return pages.map((props: Props) => {
124		return { params: { listing: props.slug }, props };
125	});
126}
127
128const makePaginationLinks = () => {
129	const allServices = parentSection.services || [];
130	const index = allServices.findIndex((item) => item.name === name);
131	const previousItem = index > 0 ? allServices[index - 1].name : null;
132	const nextItem =
133		index < allServices.length - 1 ? allServices[index + 1].name : null;
134	return { previous: previousItem, next: nextItem };
135};
136
137const { previous, next } = makePaginationLinks();
138
139const ignoredSites = ['github.com', 'wikipedia.'];
140
141const githubData = github ? await fetchGitHubStats(github) : null;
142const privacyData = tosdrId ? await fetchTosdrPrivacy(tosdrId) : null;
143const iosData = iosApp ? await fetchIosInfo(iosApp) : null;
144const androidData = androidApp ? await fetchAndroidInfo(androidApp) : null;
145const discordData = discordInvite
146	? await fetchDiscordInfo(discordInvite)
147	: null;
148const redditData = subreddit ? await fetchRedditInfo(subreddit) : null;
149const dockerData = await fetchDockerData(name);
150const websiteData =
151	url && !ignoredSites.some((s) => url.includes(s))
152		? await fetchWebsiteInfo(url)
153		: null;
154
155const serviceHistory = await fetchChangelog().then(({ entries }) => {
156	const isMatch = (c: { name: string; category: string; section: string }) =>
157		c.name === name &&
158		c.category === categoryName &&
159		c.section === parentSection.name;
160	const isHere = (m: {
161		name: string;
162		to: { category: string; section: string };
163	}) =>
164		m.name === name &&
165		m.to.category === categoryName &&
166		m.to.section === parentSection.name;
167	const results: Array<{
168		date: string;
169		type: 'added' | 'removed' | 'modified' | 'moved' | 'renamed';
170		fields?: string[];
171		from?: { category: string; section: string };
172		previousName?: string;
173		pr?: import('@utils/fetch-changelog').ChangelogPr | null;
174	}> = [];
175	for (const e of entries) {
176		const s = e.changes?.services;
177		const added = (s?.added || []).find(isMatch);
178		const removed = (s?.removed || []).find(isMatch);
179		const modified = (s?.modified || []).find(isMatch);
180		const moved = (s?.moved || []).find(isHere);
181		const renamed = (s?.renamed || []).find(isHere);
182		if (added) results.push({ date: e.date, type: 'added', pr: e.pr });
183		else if (removed) results.push({ date: e.date, type: 'removed', pr: e.pr });
184		else if (modified)
185			results.push({
186				date: e.date,
187				type: 'modified',
188				fields: modified.fields,
189				pr: e.pr,
190			});
191		else if (renamed)
192			results.push({
193				date: e.date,
194				type: 'renamed',
195				previousName: renamed.previousName,
196				from: renamed.from,
197				pr: e.pr,
198			});
199		else if (moved)
200			results.push({ date: e.date, type: 'moved', from: moved.from, pr: e.pr });
201	}
202	return results;
203});
204
205const findPrivacyPolicyLink = () => {
206	if (!privacyData) return null;
207	const docs = privacyData?.parameters?.documents;
208	if (docs) {
209		const pp = (docs || []).find((doc) =>
210			doc.name.toLowerCase().includes('privacy policy'),
211		);
212		if (pp) return pp.url;
213	}
214	return `https://tosdr.org/en/service/${tosdrId}`;
215};
216
217const privacyPolicyLink = findPrivacyPolicyLink();
218
219const catSlug = slugify(categoryName);
220const secSlug = slugify(parentSection.name);
221
222const getApiEndpoint = () => {
223	return `https://api.awesome-privacy.xyz/${catSlug}/${secSlug}/${slugify(name)}`;
224};
225
226const makeSoftwareSchema = () => {
227	const operatingSystem = [
228		iosApp && 'iOS',
229		androidApp && 'Android',
230		url && 'Web',
231	].filter(Boolean);
232	const plainDescription = (description || '')
233		.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1')
234		.replace(/[*_`~]/g, '')
235		.trim();
236	return {
237		'@context': 'https://schema.org',
238		'@type': 'SoftwareApplication',
239		name,
240		description: plainDescription || makeDescriptionTag(),
241		url,
242		applicationCategory: parentSection.name,
243		...(operatingSystem.length && {
244			operatingSystem: operatingSystem.join(', '),
245		}),
246		...(github && { codeRepository: `https://github.com/${github}` }),
247	};
248};
249---
250
251<Layout
252	title={makePageTitle()}
253	keywords={makeKeyWordTag()}
254	description={makeDescriptionTag()}
255	breadcrumbs={makeBreadcrumbs()}
256	customSchemaJson={makeSoftwareSchema()}
257>
258	<main>
259		<ListingHero
260			service={Astro.props}
261			parentSection={parentSection}
262			categoryName={categoryName}
263			privacyPolicyLink={privacyPolicyLink}
264		/>
265		{
266			privacyData && privacyData.parameters.points.length > 0 && (
267				<section>
268					<h2>{name} Privacy Policy</h2>
269					<PrivacyPolicyDetails privacyData={privacyData} />
270				</section>
271			)
272		}
273		{
274			github && githubData && (
275				<section class="github-wrap">
276					<h2>{name} Source Code</h2>
277					<GitHubDetailedInfo gitHubData={githubData} repo={github} />
278				</section>
279			)
280		}
281		{
282			websiteData && (
283				<section>
284					<h2>{name} Website</h2>
285					<WebsiteDetailedInfo url={url} websiteInfo={websiteData} />
286				</section>
287			)
288		}
289		{
290			androidData && !androidData.error && (
291				<section>
292					<h2>{name} Android App</h2>
293					<AndroidAppDetailedInfo androidData={androidData} />
294				</section>
295			)
296		}
297		{
298			iosData &&
299				typeof iosData === 'object' &&
300				Object.keys(iosData).length > 0 && (
301					<section>
302						<h2>{name} iOS App</h2>
303						<IosAppDetailedInfo url={url} iosData={iosData} />
304					</section>
305				)
306		}
307		{
308			dockerData && dockerData.found && (
309				<section>
310					<h2>{name} Docker</h2>
311					<DockerDetailedInfo docker={dockerData} />
312				</section>
313			)
314		}
315		{
316			(discordData || redditData) && (
317				<section>
318					<h2>{name} Socials</h2>
319					<div class="social-wrap">
320						{discordData && <DiscordDetailedInfo discordData={discordData} />}
321						{redditData && <RedditDetailedInfo redditData={redditData} />}
322					</div>
323				</section>
324			)
325		}
326
327		<section>
328			<h2>{name} Reviews</h2>
329			<Comments client:visible />
330		</section>
331
332		<section>
333			<h2>More {parentSection.name}</h2>
334			<ServiceList
335				services={filterServices()}
336				subHeading={true}
337				noGitHubMetrics={true}
338				buttonLink={`/${catSlug}/${secSlug}`}
339				categoryName={categoryName}
340				sectionName={parentSection.name}
341			/>
342		</section>
343		<section>
344			<h2>About the Data: {name}</h2>
345			<DataActions
346				client:load
347				categoryName={categoryName}
348				sectionName={parentSection.name}
349				serviceName={name}
350				history={serviceHistory}
351			/>
352			<h3>API</h3>
353			<p>
354				You can access {name}'s data programmatically via our API. Simply make a <code
355					>GET</code
356				> request to:
357			</p>
358			<pre><a href={getApiEndpoint()}><code>{getApiEndpoint()}</code></a></pre>
359			<p>
360				The REST API is free, no-auth and CORS-enabled. To learn more, view the <a
361					href="/api">Swagger Docs</a
362				> or read the <a href="/about#api">API Usage Guide</a>.
363			</p>
364		</section>
365
366		<section>
367			<h2>Share {name}</h2>
368			<p>
369				Help your friends compare {parentSection.name}, and pick
370				privacy-respecting software and services.<br />
371				Share {name} and Awesome Privacy with your network!
372				<div>
373					<SocialShare
374						url={`${site}/${catSlug}/${secSlug}/${slugify(name)} `}
375						title={`Checkout ${name}! \n`}
376						description={`Compare #${name} and other privacy-respecting ${parentSection.name} at ` +
377							`Awesome-Privacy.xyz, the free and open source list of private software alternatives. ` +
378							`#privacy #opensource #awesomeprivacy by @Lissy_Sykes`}
379					/>
380				</div>
381			</p>
382		</section>
383
384		<div class="pagination-navigation">
385			{
386				previous ? (
387					<Button url={`/${catSlug}/${secSlug}/${slugify(previous)}`}>
388						<span>← Previous</span>
389						<p>{previous}</p>
390					</Button>
391				) : (
392					<p class="nothing" />
393				)
394			}
395			<a href={`/${catSlug}/${secSlug}`} class="go-to-category">
396				View {parentSection.name} ({(parentSection.services || []).length})
397			</a>
398			{
399				next && (
400					<Button url={`/${catSlug}/${secSlug}/${slugify(next)}`}>
401						<span>Next →</span>
402						<p>{next}</p>
403					</Button>
404				)
405			}
406		</div>
407	</main>
408</Layout>
409
410<style lang="scss">
411	main {
412		margin: var(--space-lg) auto;
413		padding: var(--space-md);
414		width: var(--width-container);
415		max-width: var(--width-container-max);
416		position: relative;
417		@media (max-width: 768px) {
418			max-width: 95%;
419			padding: var(--space-sm);
420			margin: 0 auto;
421		}
422	}
423
424	section {
425		margin: var(--space-md) 0 var(--space-2xl) 0;
426		padding: var(--space-md);
427		min-height: 8rem;
428		position: relative;
429		border: var(--border-heavy);
430		box-shadow: var(--shadow-lg);
431		background: var(--accent-fg);
432	}
433
434	p {
435		margin: var(--space-xs) 0 var(--space-sm) 0;
436	}
437
438	h2 {
439		font-size: var(--text-3xl);
440		margin: -2rem 0 var(--space-md) -2rem;
441		box-shadow: var(--shadow-lg);
442		background: var(--accent);
443		color: var(--accent-fg);
444		width: fit-content;
445		padding: var(--space-xs) var(--space-sm);
446		@media (max-width: 768px) {
447			margin: -2rem auto var(--space-lg) auto;
448		}
449	}
450
451	h3 {
452		font-size: var(--text-lg);
453		margin-bottom: 0;
454	}
455
456	pre a {
457		text-decoration: none;
458		color: var(--foreground);
459		code {
460			background: var(--code-bg);
461			padding: 0.2rem 0.4rem;
462			border-radius: var(--curve-sm);
463			font-family: var(--font-code);
464			font-size: var(--text-sm);
465			@media (max-width: 768px) {
466				white-space: break-spaces;
467			}
468		}
469	}
470
471	.social-wrap {
472		display: flex;
473		gap: var(--space-md);
474		flex-wrap: wrap;
475		justify-content: space-between;
476	}
477</style>